<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Announcement {
	private $CI;
	
	public function __construct() {
		$this->CI = &get_instance();
		$this->CI->load->model('Announcement_Model', 'announcementmodel');
	}
	
	public function get_announcement($offset, $limit) {
		return $this->CI->announcementmodel->get_announcement($offset, $limit);
	}
	
	public function get_announcement_by_id($id) {
		return $this->CI->announcementmodel->get_announcement_by_id($id);
	}
	
	public function add_announcement($creator, $title, $content) {
		if ($this->CI->authentication->is_allowed('CREATE_ANNOUNCEMENT')) {
			return $this->CI->announcementmodel->add_announcement($creator, $title, $content);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function edit_announcement($id, $creator, $title, $content) {
		if ($this->CI->authentication->is_allowed('EDIT_ANNOUNCEMENT')) {
			return $this->CI->announcementmodel->edit_announcement($id, $creator, $title, $content);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function delete_announcement($id) {
		if ($this->CI->authentication->is_allowed('DELETE_ANNOUNCEMENT')) {
			return $this->CI->announcementmodel->delete_announcement($id);
		} else {
			$this->CI->session->set_flashdata('error', 'Role tidak boleh mengakses fitur ini.');
			return FALSE;
		}
	}
	
	public function count_announcement() {
		return $this->CI->announcementmodel->count_announcement();
	}
}